<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title>示例</title>
    <script type="text/javascript">
        var str = "Every man in the world! Every woman on earth!";

        patt = /man/g; // 匹配所有包含的内容
        str2 = str.replace(patt, "person");
        document.write(str2 + "<br />");

        patt = /(wo)?man/g;
        patt.compile(patt);
        str2 = str.replace(patt, "person");
        document.write(str2 + "<br />");



        var str = "欢迎来到广科院";
        var reg = new RegExp("广科", "g");
        var result;

        while ((result = reg.exec(str)) != null) {
            document.write(result);
            document.write("<br />");
            document.write(reg.lastIndex);
        }
    </script>

</head>

<body>
</body>

</html>